package com.xueyl.springboot;

import org.springframework.core.convert.converter.Converter;
import org.springframework.core.serializer.support.DeserializingConverter;
import org.springframework.core.serializer.support.SerializingConverter;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

public class RedisObjectSerializer implements RedisSerializer<Object> {
	
	private Converter<Object, byte[]> serializer = new SerializingConverter();
	private Converter<byte[], Object> deserialize = new DeserializingConverter();

	@Override
	public byte[] serialize(Object obj) throws SerializationException {
		if(null == obj) return null;
		return serializer.convert(obj);
	}

	@Override
	public Object deserialize(byte[] bytes) throws SerializationException {
		if(null == bytes) return null;
		return deserialize.convert(bytes);
	}

}
